package com.bjx.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjx.api.flow.domain.vo.FlowDisposeVO;
import com.bjx.common.core.domain.R;
import com.bjx.common.core.domain.group.Update;
import com.bjx.demo.domain.query.VacationQuery;
import com.bjx.demo.domain.vo.VacationVO;
import com.bjx.demo.service.IVacationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 请假信息控制器
 * @author: liushuai
 * @date: 2022/10/20
 */
@RequestMapping("/vacation")
@Tag(name = "请假信息控制器")
@RestController
public class VacationController {

    @Autowired
    private IVacationService vacationService;

    /**
     * 分页查询请假信息列表
     * @param vacationQuery
     * @return: R<IPage<VacationVO>>
     * @Author: liushuai
     * @Date: 2022/10/20
     */
    @Operation(summary = "分页查询请假信息列表")
    @GetMapping("listVacationPage")
    public R<IPage<VacationVO>> listVacationPage(VacationQuery vacationQuery) {
        IPage<VacationVO> page = vacationService.listVacationPage(vacationQuery);
        return R.success(page);
    }

    /**
     * 根据请假信息id查询请假信息
     * @param vacationId
     * @return:R<VacationVO>
     * @Author: liushuai
     * @Date: 2022/10/20
     */
    @Operation(summary = "根据请假信息id查询请假信息")
    @GetMapping("selectVacationByVacationId")
    public R<VacationVO> selectVacationByVacationId(@RequestParam Long vacationId){
        VacationVO vo = vacationService.selectVacationByVacationId(vacationId);
        return R.success(vo);
    }

    /**
     * 根据请假信息id删除请假信息
     * @param vacationId
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/20
     */
    @Operation(summary = "根据请假信息id删除请假信息")
    @GetMapping("deleteVacationByVacationId")
    public R deleteVacationByVacationId(@RequestParam Long vacationId){
        vacationService.deleteVacationByVacationId(vacationId);
        return R.successMsg("删除请假信息成功");
    }

   /**
    * 新增请假信息
    * @param vacationVO
    * @return: R
    * @Author: liushuai
    * @Date: 2022/10/20
    */
   @Operation(summary = "新增请假信息")
   @PostMapping("insertVacation")
   public R insertVacation(@RequestBody @Validated VacationVO vacationVO){
      vacationService.insertVacation(vacationVO);
      return R.successMsg("新增请假信息成功");
   }

    /**
     * 修改请假信息
     * @param vacationVO
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/20
     */
    @Operation(summary = "修改请假信息")
    @PostMapping("updateVacation")
    public R updateVacation(@RequestBody @Validated(Update.class) VacationVO vacationVO){
        vacationService.updateVacation(vacationVO);
        return R.successMsg("修改请假信息成功");
    }

    /**
     * 发起请假流程
     * @param vacationVO
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/20
     */
    @Operation(summary = "发起请假流程")
    @PostMapping("startVacationFlow")
    public R startVacationFlow(@RequestBody @Validated(Update.class) VacationVO vacationVO){
        vacationService.startVacationFlow(vacationVO);
        return R.successMsg("发起请假流程成功");
    }
    

    /**
     * 请假流程处理
     * @param flowDisposeVO
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/20
     */
    @Operation(summary = "请假流程处理")
    @PostMapping("vacationFlowDispose")
    public R vacationFlowDispose(@RequestBody FlowDisposeVO flowDisposeVO){
        vacationService.vacationFlowDispose(flowDisposeVO);
        return R.success("处理成功");
    }


}
